package xiaopiya.robot.handler.rss;

import xiaopiya.robot.handler.AbstractMessageHandler;
import xiaopiya.robot.handler.rss.tool.IRssBookingService;

/**
 * @author Ray (ayufox@gmail.com)
 * @version 0.1
 */
public class RssBookMessageHandler extends AbstractMessageHandler
{
	private IRssBookingService rssBookingService;

	public void setRssBookingService(IRssBookingService rssBookingService)
	{
		this.rssBookingService = rssBookingService;
	}

	protected String handle(String from, String params) throws Exception
	{
		String[] array = params.split(" ");
		if (array.length != 2)
		{
			return "请指定正确的频道格式，譬如tom lq";
		}
		if (this.rssBookingService.book(from,
				new ChannelKey(array[0], array[1])))
		{
			return "频道订阅成功";
		}
		else
		{
			return "频道 " + params + "不支持";
		}
	}
}
